#include "taskqueue.hpp"
taskqueue::taskqueue(size_t capa)
    : _capacity(capa), _que(), _mutex(), _notEmpty(), _notFull()
{
}
taskqueue::~taskqueue()
{
}
void taskqueue::push(const int &val)
{
    unique_lock<mutex> ul(_mutex);
    while (full())
    {
        _notFull.wait(ul);
    }
    _que.push(val);
    _notEmpty.notify_one();
}
int taskqueue::pop()
{
    unique_lock<mutex> ul(_mutex);
    while (empty())
    {
        _notEmpty.wait(ul);
    }
    int tmp = _que.front();
    _que.pop();
    _notFull.notify_one();
    return tmp;
}
bool taskqueue::full() const
{
    return _capacity == _que.size();
}
bool taskqueue::empty() const
{
    return 0 == _que.size();
}